#!/usr/bin/env python

from test0  import *
from test0 import WidgetInd as WI
from test0 import WidgetArg as WA

w = Widget(WI("window"))
mf = Widget(WI("menu"))
me = Widget(WI("menu"))
f = Widget(WI("menu_button"))
g = Widget(WI("group"))
o = Widget(WI("menu_button"))
e = Widget(WI("menu_button"))
u = Widget(WI("menu_button"))
n = Widget(WI("menu_button"))
q = Widget(WI("menu_button"))
l = Widget(WI("field"));

def new_callback(sender):
  print "new_callback(sender)"

def open_callback(sender):
  print "open_callback(sender)"

def quit_callback(sender):
  print "quit_callback(sender)"

def undo_callback(sender):
  print "undo_callback(sender)"

if __name__ == "__main__":
  init()

  w.create()
  w.set_arg (WA(
    "set",
    [
    ("title", "Main Window"),
    ("dim", (100, 100))
    ]))

  g.create()
  l.set_parent(g)
  l.create()
  l.set_arg (WA(
    "set",
    [
    ("text", "field"),
    ("dim", (100, 100))
    ]))


  f.set_parent(g)
  f.create()
  f.set_arg (WA(
    "set",
    [
    ("text", "file"),
    ]))

  mf.set_parent(f)
  mf.create()
  f.set_callback("post_menu",mf)

  n.set_parent(mf)
  n.create()
  n.set_arg (WA(
    "set",
    [
      ("text", "new")
      ]))
  n.set_callback("sender", new_callback)
  
  o.create()
  o.set_arg (WA(
    "set",
    [
    ("text", "open"),
    ]))
  o.set_callback("sender", open_callback)

  q.create()
  q.set_arg (WA(
    "set",
    [
      ("text", "quit"),
      ]))
  q.set_callback("sender", quit_callback)

  e.set_parent(g)
  e.create()
  e.set_arg (WA(
    "set",
    [
    ("text", "edit"),
    ]))

  me.set_parent(e)
  me.create()
  e.set_callback("post_menu",me)

  u.set_parent(me)
  u.create()
  u.set_arg (WA(
    "set",
    [
      ("text", "undo"),
      ]))
  u.set_callback("sender", undo_callback)

  w.realize()
  main_loop()
  print "Goodbye"
